﻿using languageSite.ViewModels.Common;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;

public class CustomExceptionFilter : IExceptionFilter
{
    private readonly ILogger<CustomExceptionFilter> _logger;

    public CustomExceptionFilter(ILogger<CustomExceptionFilter> logger)
    {
        _logger = logger;
    }

    public void OnException(ExceptionContext context)
    {
        _logger.LogError($"An error occurred: {context.Exception}");
        context.Result = new ObjectResult(new ResModel() {state = 1001, data="接口异常",detail="具体查看日志"});
        context.ExceptionHandled = true;
    }
}
